//
//  LbtCell.m
//  A段项目
//
//  Created by dllo on 16/1/30.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "LbtCell.h"
#import "LbtWebView.h"
#import "ViewController.h"


@interface LbtCell ()<UIScrollViewDelegate>

@property (nonatomic, retain) UIPageControl *pageControl;



@end

@implementation LbtCell

{
    NSInteger count1;
    
}

- (void)dealloc {
    
    [_pageControl release];
    [_scroll release];
    
    [super dealloc];
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.scroll = [[UIScrollView alloc] init];
        
        [self.contentView addSubview:self.scroll];  //添加轮播图.
        
        [_scroll release];
        
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.scroll.frame = self.bounds;
    
    self.scroll.contentSize = CGSizeMake(self.bounds.size.width * count1, self.bounds.size.height);
    
    self.scroll.pagingEnabled = YES; //允许翻页.
    
    self.pageControl = [[UIPageControl alloc] init];
    
    [self.contentView addSubview:self.pageControl];
    
    self.scroll.delegate = self;
    
    self.pageControl.numberOfPages = count1;
    
    self.pageControl.frame = CGRectMake((self.frame.size.width - 100)/2, self.frame.size.height - 20, 100, 20);
    
    self.pageControl.backgroundColor = [UIColor blueColor];
    
    self.scroll.showsHorizontalScrollIndicator = NO;
    
    self.pageControl.hidden = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    [self.scroll addGestureRecognizer:tap];
    
}

- (void)tapAction:(UITapGestureRecognizer *)tap {
    
    
    [self.delegate Lbtcell:self :self.pageControl.currentPage];
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
   
    
    self.pageControl.currentPage = self.scroll.contentOffset.x/self.scroll.frame.size.width;
    
    
}


/**返回 imageView 的个数. */

- (NSInteger)passedImageNumber:(NSInteger)count {
    
    count1 = count;
    
    
    return count;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
